home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
UTIL
/
Folder・Icon・Opener 1.0.1.sit
/
Folder•Icon•Opener 1.0.1
/
source code
/
sources
/
FIOpen.copy.c
< prev
next >
Wrap
Text File
|
1996-05-05
|
6KB
|
226 lines
/*
*--------------------------------------------------------------
* FIOpen.copy.c
*--------------------------------------------------------------
* Copyright ゥ Fumio Rokkaku, 1996
*--------------------------------------------------------------
*/
#pragma once
/* System Headers */
#include <Memory.h>
#include <QuickDraw.h>
#include <QDOffscreen.h>
#include <OSUtils.h>
#include <Scrap.h>
#include <icons.h>
#include <Files.h>
#include <Finder.h>
#include <Gestalt.h>
#include <Errors.h>
/* Project Headers */
#include "FIOpen.h"
/*
*--------------------------------------------------------------
* static function prototypes
*--------------------------------------------------------------
*/
pascal OSErr CopyIconToScrap(ResType, Handle *, void *);
static OSErr CopyIconsPictToScrap(Handle);
static OSErr MakeIconsPict(Handle, PicHandle *);
/*
*--------------------------------------------------------------
* GetIconToScrap
*--------------------------------------------------------------
* get an icon suite of the folder and copy it to the clipboard
*--------------------------------------------------------------
*/
OSErr GetIconToScrap(const FSSpecPtr theSpec)
{
Handle aSuite = nil;
long gestaltAnswer;
OSErr result;
/* check scriptable Finder presense */
result = Gestalt(gestaltFinderAttr, &gestaltAnswer);
if (result != noErr || (gestaltAnswer & (1 << gestaltOSLCompliantFinder)) == 0) {
return (noErr);
}
/* show copying message */
OpenCopyingDialog();
/* then get the icon suite */
result = GetIconSuiteViaFinder(theSpec, &aSuite);
if ((result == noErr) && (aSuite != nil)) {
IconActionUPP CopyIconUPP = nil;
ShowCopyingIcon(aSuite);
CopyIconUPP = NewIconActionProc(CopyIconToScrap);
if (CopyIconUPP != nil) {
ZeroScrap();
result = ForEachIconDo(aSuite, kSelectorAllAvailableData, CopyIconUPP, nil);
DisposeRoutineDescriptor(CopyIconUPP);
if (result == noErr) {
CopyIconsPictToScrap(aSuite);
}
} else {
result = MemError();
}
}
/* cleanup */
if (aSuite != nil) {
DisposeIconSuite(aSuite, false);
}
CloseCopyingDialog();
return (result);
}
/*
*--------------------------------------------------------------
* CopyIconToScrap
*--------------------------------------------------------------
* copy each icon of the icon suite to clipboard
*--------------------------------------------------------------
*/
pascal OSErr CopyIconToScrap(ResType theType, Handle *theIcon, void *usrPtr)
{
#pragma unused (usrPtr)
Handle anIcon = *theIcon;
OSErr result = noErr;
if (anIcon != nil) {
Size itsSize;
itsSize = GetHandleSize(anIcon);
if (itsSize > 0) {
UInt8 hState = HGetState(anIcon);
HLock(anIcon);
result = PutScrap(itsSize, theType, *anIcon);
HSetState(anIcon, hState);
}
}
return (result);
}
/*
*--------------------------------------------------------------
* CopyIconsPictToScrap
*--------------------------------------------------------------
* make a picture of the suite and copy it to the clipboard
*--------------------------------------------------------------
*/
static OSErr CopyIconsPictToScrap(Handle theSuite)
{
OSErr result = unimpErr;
/* check the offscreen graphic capability */
if (gQDVersion >= gestalt32BitQD) {
PicHandle aPicture = nil;
result = MakeIconsPict(theSuite, &aPicture);
if ((result == noErr) && (aPicture != nil)) {
Size itsSize = GetHandleSize((Handle)aPicture);
HLock((Handle)aPicture);
result = PutScrap(itsSize, 'PICT', *aPicture);
HUnlock((Handle)aPicture);
}
if (aPicture != nil) {
KillPicture(aPicture);
}
}
return (result);
}
/*
*--------------------------------------------------------------
* MakeIconsPict
*--------------------------------------------------------------
* create a picture of the icon suite using GWorld
*--------------------------------------------------------------
*/
static OSErr MakeIconsPict(Handle theSuite, PicHandle *thePict)
{
PicHandle aPict = nil;
OSErr result = noErr;
if (theSuite != nil) {
GWorldPtr aGWorld1 = nil;
GWorldPtr aGWorld2 = nil;
Rect iconRect;
RectPtr aBounds = &iconRect;
SetRect(aBounds, 0, 0, 32, 32);
result = NewGWorld(&aGWorld1, 8, aBounds, nil, nil, 0);
if (result == noErr) {
result = NewGWorld(&aGWorld2, 8, aBounds, nil, nil, 0);
}
if (result == noErr) {
GrafPtr savePort;
GWorldPtr saveGWld;
GDHandle saveGDev;
PixMapHandle aPixMap1 = nil;
PixMapHandle aPixMap2 = nil;
/* get the ofscreen pixcel maps and lock them */
aPixMap1 = GetGWorldPixMap(aGWorld1);
aPixMap2 = GetGWorldPixMap(aGWorld2);
LockPixels(aPixMap1);
LockPixels(aPixMap2);
/* save current offscreen devices */
GetPort(&savePort);
GetGWorld(&saveGWld, &saveGDev);
/* plot the icon suite to the GWorld 1 */
SetGWorld(aGWorld1, nil);
ForeColor(blackColor);
BackColor(whiteColor);
EraseRect(aBounds);
result = PlotIconSuite(aBounds, kAlignNone, kTransformNone, theSuite);
/* make a picture of the suite */
if (result == noErr) {
RgnHandle maskRgn = NewRgn();
/* make an icon mask of the suite*/
result = IconSuiteToRgn(maskRgn, aBounds, kAlignNone, theSuite);
if (result == noErr) {
/* copy the GWorld 1 PixMap into the GWorld 2 */
SetGWorld(aGWorld2, nil);
ForeColor(blackColor);
BackColor(whiteColor);
EraseRect(aBounds);
/* record the GWorld 2 PixMap into the picture */
aPict = OpenPicture(aBounds);
if (aPict != nil) {
SetClip(maskRgn);
CopyBits((BitMapPtr)*aPixMap1, (BitMapPtr)*aPixMap2,
aBounds, aBounds, srcCopy, maskRgn);
ClosePicture();
}
}
DisposeRgn(maskRgn);
}
/* unlock the offscreen pixcel maps */
UnlockPixels(aPixMap1);
UnlockPixels(aPixMap2);
/* restore saved offscreen devices */
SetGWorld(saveGWld, saveGDev);
SetPort(savePort);
}
/* cleanups */
if (aGWorld1 != nil) {
DisposeGWorld(aGWorld1);
}
if (aGWorld2 != nil) {
DisposeGWorld(aGWorld2);
}
}
*thePict = aPict;
return (result);
}